#include "ObjectFactory.h"

ObjectFactory::ObjectFactory()
{
    _builtinTable.insert("NUL", "\x0");
    _builtinTable.insert("SOH", "\x1");
    _builtinTable.insert("STX", "\x2");
    _builtinTable.insert("ETX", "\x3");
    _builtinTable.insert("EOT", "\x4");
    _builtinTable.insert("ENQ", "\x5");
    _builtinTable.insert("ACK", "\x6");
    _builtinTable.insert("HT" , "\x9");
    _builtinTable.insert("LF" , "\xA");
    _builtinTable.insert("CR" , "\xD");
    _builtinTable.insert("NAK", "\x15");
    _builtinTable.insert("SYN", "\x16");
    _builtinTable.insert("ETB", "\x17");
    _builtinTable.insert("GS" , "\x1D");
    _builtinTable.insert("RS" , "\x1E");
    _builtinTable.insert("SP" , "\x20");
}

ObjectPtr ObjectFactory::GetObject(const QString& name, const QByteArray& value)
{
    return _producedObjects.contains(name) ? _producedObjects[name] : _producedObjects[name] = ProduceNew(name, value);
}

ObjectPtr ObjectFactory::ProduceNew(const QString& name, const QByteArray& value)
{
	bool builtin = _builtinTable.contains(name);
    return ObjectPtr(new Object(builtin ? _builtinTable[name] : value, builtin));
}
